package com.cskaoyan.weixin.service;

import com.cskaoyan.mapper.CommentMapper;
import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.weixin.bean.comment.CommentCountVO;
import com.cskaoyan.weixin.bean.comment.CommentListVO;
import com.cskaoyan.weixin.bean.comment.CommentVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentWxServiceImpl implements CommentWxService {

    @Autowired
    CommentMapper commentMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public CommentCountVO countOfComment(Integer valueId, Byte type) {
        Integer allCount = commentMapper.queryCommentByPicUrls(valueId, type, (byte) 0);
        Integer hasPicCount = commentMapper.queryCommentByPicUrls(valueId, type, (byte) 1);
        CommentCountVO commentCountVO = new CommentCountVO(hasPicCount, allCount);
        return commentCountVO;
    }

    @Override
    public CommentListVO queryCommentOfGoods(Integer valueId, Byte type, Integer size,
                                             Integer page, Byte showType) {
        PageHelper.startPage(page, size);

        List<CommentVO> commentVOList = commentMapper.queryCommentOfGoods(valueId, type, showType);

        PageInfo pageInfo = new PageInfo(commentVOList);
        long total = pageInfo.getTotal();

        CommentListVO commentListVO = new CommentListVO();
        commentListVO.setData(commentVOList);
        commentListVO.setCount((int) total);
        commentListVO.setCurrentPage(page);

        return commentListVO;
    }

}
